﻿using System;
using System.Collections.Generic;
using UniRx;
using UnityEngine;

public class PlayerController : UnitControllerBase
{
    protected override void OnInit()
    {
        RegisterStream("horizontal", InputManager.horizontal);
        RegisterStream("vertical", InputManager.vertical);
        RegisterStream("jump", CommandManager.FindStream("jump"));
        RegisterStream("standSkill", GetSkillStream(SkillEffectiveState.Standing));
        RegisterStream("airborneSkill", GetSkillStream(SkillEffectiveState.Airborne));
        RegisterStream("interact", CommandManager.FindStream("interact"));
    }

    private IObservable<int> GetSkillStream(SkillEffectiveState state)
    {
        var skills = entity.skillManager.skills.FindAll(s => s.config.effectiveStates.HasFlag(state));
        var standStreams = new List<IObservable<int>>();
        for (int i = 0; i < skills.Count; i++)
        {
            var skill = skills[i];
            // TODO 动态键位
            var stream = CommandManager.FindStream(skill.config.axisName).Select(_ => skill.config.id);
            standStreams.Add(stream);
        }
        return Observable.Merge(standStreams);
    }
}